﻿//<--joan 2007/8/27 message const
var AttConfirm="Have you checked the attached files?";
var SaveInfo="Are you sure to save the information?";
var RejectApp="Are you sure to reject the application?";
var RejectMM="Are you sure to reject the meeting minutes?";
var DeleteItem="Are you sure to delete this item?";


//-->end
// add by kevin, to allow disable all controls on screen.
/*
var sHiddenWindow = "<div id='HideWindow' ";
sHiddenWindow += "style='visibility:hidden;background:#000;-moz-opaty:0.2; filter:alpha(opacity=20);";
sHiddenWindow += "position:absolute;z-index:1;top:0;left:0;height:100%; width:100%'>";
sHiddenWindow += "</div>";
document.write(sHiddenWindow);
*/

/*
for(i=0;i<document.all.length;i++)
{
	var btn = document.all[i];
	if(btn.id != null && btn.id.length >=9 && btn.id.indexOf('btnExport') >= 0)
	{
		alert();
		btn.onclick = DisablePage;
	}
}

var btns=document.getElementsByTagName("INPUT")
for(i=0;i<btns.length;i++)

{
	var btn = btns[i];
	alert();
	if(btn.id != null && btn.id.indexOf('Attach')>= 0)
	{
		btn.onclick = DisablePage;
	}
}
*/
function DisablePage()
{
	document.getElementById("HideWindow").style.visibility = "visible";
}
function EnablePage()
{
	document.getElementById("HideWindow").style.visibility = "hidden";
}
function PopupWindow(url)
{
	window.open(url,"","status=yes,toolbar=no,menubar=no,resizable=yes");
}

function On_Window_Submit()
{
	$("#dialog-message").dialog({
		modal: true
	});
}
function After_Window_Submit()
{
	if (document.getElementById("HideWindow")!=null)
		document.getElementById("HideWindow").visibility="hidden";
}
//close the current popup window and redirect it's parent window
// window ----> the window to close
// url -------> the destination where should the window's parent be directed
function CloseAndRedirectParent(window, url)
{
    window.location = url;
}

//move the window to the center of the screen    
function Move2Center()
{
    window.moveTo((window.screen.width - document.body.clientWidth)/2, (window.screen.height - document.body.clientHeight)/2);
}

function ResizeDiv()
{
	document.getElementById("blockDiv").style.height = document.body.clientHeight * 0.7;
}

function SelectAll(CheckBoxControl) 
{			
	if (CheckBoxControl.checked == true) 
	{
		var i;
		for (i=0; i < document.forms[0].elements.length; i++) 
		{
			if ((document.forms[0].elements[i].type == 'checkbox') && 
			(document.forms[0].elements[i].name.indexOf('chkSelection') > -1)) 
			{
				document.forms[0].elements[i].checked = true;
			}
		}
	} 
	else 
	{
		var i;
		for (i=0; i < document.forms[0].elements.length; i++) 
		{
			if ((document.forms[0].elements[i].type == 'checkbox') && 
			(document.forms[0].elements[i].name.indexOf('chkSelection') > -1)) 
			{
				document.forms[0].elements[i].checked = false;
			}
		}
	}
}

function OnSaveAlert( SaveInfo )
{
	if( window.confirm( SaveInfo ) )
	{
		event.returnValue = true;
	}
	else
	{
		event.returnValue = false;
	}
}

function OnSubmitAlert( SubmitInfo )
{
	if( window.confirm( SubmitInfo ) )
	{
		event.returnValue = true;
	}
	else
	{
		event.returnValue = false;
	}
}
function CheckEmpty( control )
{
	var con = document.getElementById(control);
	if( con.value == "" )
	{
		con.style.background = "#FFFFC0";
		return false;		
	}
	else
	{
		con.style.background = "#FFFFFF";
		return true;
	}
}

function checkbadwords(textcontrol) 
{
	var badwords = "'\"&()<>\\";
	if (!check(textcontrol.value, badwords))
	{
		alert("Input invalid character('\"&()<>\\).");
		textcontrol.focus();
	}
}
		
function check(str, badwords)
 {
	if (typeof (str) != "string" || typeof (badwords) != "string") 
	{
		return (false);
	}
	for (i=0; i<badwords.length; i++) 
	{
		bad = badwords.charAt(i);
		for (j=0; j<str.length; j++)
		{
			if (bad == str.charAt(j)) 
			{
				return false;
				break;
			}	
		}
	}
	return true;
}

function   jsAlert(msg)   
  {   
  VBAlert(msg,0,msg);   
  
 }   

//added by joan 2007-07-07
//for adjust blockDiv automatically
var resizeCount=0;
window.onresize=WindowResize;
var objDiv =document.getElementById("blockDiv");
var winHeight=0;
var divHeight=0;
var outDivHeight=0;

if (objDiv!=null)
{
	//get window height and blockDiv height;
	winHeight=document.body.clientHeight;
    divHeight=parseInt(objDiv.style.height);
    var stampHeight=0;
    
    divHeight = winHeight-190;
    
    
    var stampCount=0;

	for (var i=0;i<document.all.length;i++)
	{
	    var objTemp=document.all[i]; 
	    if (objTemp.id !=null && objTemp.id.toUpperCase().indexOf('STAMPCELL') >= 0)
	    {
			stampHeight=objTemp.clientHeight;
			stampCount++;
		}
	}
	while (stampCount > 0)
	{
		divHeight -= stampHeight;
		stampCount-=7;
	}
	var obj_temp = document.getElementById("div_co_closeform");
	if (obj_temp != null)
	{
		divHeight = divHeight - 200;
	}
	objDiv.style.height=divHeight + "px";
	outDivHeight=winHeight-divHeight;
	WindowResize();
}

function WindowResize()
{
	
//	resizeCount++;
//	if (resizeCount==1)
//	{
//		if (objDiv!=null)
//		{
//			winHeight=document.body.clientHeight;
//			divHeight=winHeight-outDivHeight - 30;
//			objDiv.style.height=divHeight + "px";
//		}
//	}
//	else
//		resizeCount=0;

}

function rtrim(s)   
{
    var l;   
    var ret;   

    l = s.length;   
    while(s.charAt(l - 1) == " ")   
        l--;   
    ret = s.substring(0,   l);   
    return ret;   
}
    
function ltrim(s)   
{   
  var l;   
  var ret;   
    
  l = 0;   
  while(s.charAt(l) == " ")   
  l++;
  ret = s.substring(l);   
  return ret;   
  }   
    
  function trim(s)   
  {   
  return ltrim(rtrim(s));   
} 

function CheckEmailFormat(emailCtrl)
{
	var obj = document.getElementById(emailCtrl);
	if(obj!=null)
	{
		emailValue = obj.value;
		if(trim(emailValue)!='')
		{
			 if (emailValue.charAt(0)=='.' || 
			 emailValue.charAt(0)=='@'|| 
			 emailValue.indexOf('@', 0) == -1 || 
			 emailValue.indexOf('.', 0) == -1 || 
			 emailValue.lastIndexOf('@')==emailValue.length-1 || 
             emailValue.lastIndexOf('.')==emailValue.length-1)
			{
				obj.focus();
				return false;
			}
			return true;
		}
		else
		{
				return true;
		}
	}
	return false;
} 

function ConvertFormat(score)
{
	score = score * 100 + 0.5;
	score = Math.floor(score);
	score = score/100;
	return score;
}

function OpenWin(url, name, height, width) {
    var left = Get_Center(width, 'x');
    var top = Get_Center(height, 'y');
    if (top > 30) {
        top = top - 30;
    }
    window.open(url, name, "height=" + height + ",width=" + width + ",left=" + left + ",top=" + top + ",scrollbars=yes,status=no,toolbar=no,menubar=no,location=no,resizable=no");
}

function Get_Center(size, side) {
    self.y_center = (parseInt(screen.height / 2));
    self.x_center = (parseInt(screen.width / 2));
    center = eval('self.' + side + '_center-(' + size + '/2);');
    return (parseInt(center));
}

//选择单个员工放大镜 
//BaseUrl是URL的前缀，例："../../"；
//USER_IDCtr是id的控件名
//USER_NAMECtr是员工姓名的控件名；

function vela3OpenSelectSingleUserDialog(BaseUrl, USER_IDCtr, USER_CDCtr, USER_NAMECtr, TELE_CODE1Ctr, EMAILCtr) {

    var url = BaseUrl + "Common/SelectSingleUser.aspx?rdm=" + Math.random() +
		"&USER_IDCtr=" + USER_IDCtr + "&USER_CDCtr=" + USER_CDCtr + "&USER_NAMECtr=" + USER_NAMECtr + "&TELE_CODE1Ctr=" + TELE_CODE1Ctr + "&EMAILCtr=" + EMAILCtr;
    OpenDialog(url, "610", "780")
}


/* auto refresh window code : openedWindow\timer should be defined*/
function CheckopenedWindow() {
    if (openedWindow != null && openedWindow.closed) {
        this.location = this.location;
        openedWindow = null;
        clearInterval(timer);
        timer = null;
    }
}

function SetTimer() {
    if (timer == null) {
        timer = setInterval(CheckopenedWindow, 1000);
    }
}

function getCRNonB(appNo){
    //for CR appNO
    if (appNo.indexOf('CR') == 0 || appNo.indexOf('OCR') == 0 || appNo.indexOf('IBG') == 0) {
        var appNoResolved = appNo;
        var DashD = '';
        // for CR My Draft
        if (appNo.substring(appNo.length - 2, appNo.length) == '-D') {
            appNoResolved = appNo.substring(0, appNo.length - 2);
            DashD = '-D';
        }
        if (appNoResolved.substring(appNoResolved.length - 2, appNoResolved.length) == '-B') {
            appNoResolved = appNoResolved.substring(0, appNoResolved.length - 2);
        }
        return appNoResolved + DashD;
    }
    else {
        return appNo;
    }
}

////remove CR -B
//$(function() {
//    $(".hand_span").each(function() {
//        var appNo = $(this).text();
//        $(this).text(getCRNonB($.trim(appNo)));
//    });
//});

